package com.itheima.ydd.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.ydd.dto.Information;

import java.util.List;

public class ConvertPageInfoUtil {
    private ConvertPageInfoUtil(){}

    public static Information getPage(IPage page, List records){
        Information information = new Information();
        information.setCount(page.getTotal());
        information.setCurrentPage(page.getCurrent());
        information.setPageSize(page.getSize());
        Long count = information.getCount();
        Long pageSize1 = information.getPageSize();
        Long totalPages = count % pageSize1 == 0 ? (count % pageSize1) : (count / pageSize1 + 1);
        information.setTotalPages(totalPages);
        information.setData(records);
        return information;
    }
}